function Foo(name) {
  if(!this instanceof Foo){
    return new Foo();
  }
  this.name = name;
  this.sayName = function() {
    console.log(this.name);
  };
}

const x1 = new Foo("x1");
x1.sayName();

const x2 = Foo.call(x1, 'x2');

x2.sayName();